package com.ebt.m.policy.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.commons.buscomponent.listview.BaseListView;
import com.ebt.m.commons.buscomponent.listview.ISectionFactory;
import com.ebt.m.policy.presenter.BrandsProductsPresenter;

import java.util.Map;

import static com.ebt.m.policy.presenter.BrandsProductsPresenter.DATA_VIEW_TYPE;
import static com.ebt.m.policy.presenter.BrandsProductsPresenter.TITLE_VIEW_YTPE;


/**
 * @author Damon.Han
 */
public class BrandsProductListView extends BaseListView<BrandsProductsPresenter> {
    Map<String, String> params;

    public BrandsProductListView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BrandsProductListView(Context context) {
        this(context, null);
    }

    public BrandsProductListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mRefreshLayout.setRefreshNeeded(false);
    }


    @Override
    protected ISectionFactory createViewFactory() {
        return viewType -> {
            if (viewType == TITLE_VIEW_YTPE) {
                BrandsProductViewTitle titleView = new BrandsProductViewTitle(getContext());
                return titleView;
            } else if (viewType == DATA_VIEW_TYPE) {
                BrandsProductViewItem appsViewItem = new BrandsProductViewItem(getContext());
                return appsViewItem;
            }
            return null;
        };
    }


    @Override
    protected BrandsProductsPresenter createPresenter() {
        return new BrandsProductsPresenter(getContext(), this);
    }

    @Override
    public void loadNext() {
        mPresenter.loadNext(params);
    }

    @Override
    public void update(Object... args) {
        super.update(args);
        if (args != null && args.length > 0) {
            params = (Map<String, String>) args[0];
        }
        mPresenter.loadNew(params);
    }

    @Override
    protected boolean createFootView() {
        return true;
    }

    @Override
    protected View configEmptyView() {
        View emptyContent = LayoutInflater.from(getContext()).inflate(R.layout.layout_product_search_empty, null);
        ImageView imageView = (ImageView) emptyContent.findViewById(R.id.img_empty);
        TextView textView = (TextView) emptyContent.findViewById(R.id.mession_empty);
        imageView.setBackgroundResource(R.drawable.ic_empty_product);
        textView.setText("没有相关产品");
        return emptyContent;
    }


}
